package org.hxzon.configdesigner.web.services;

import org.apache.tapestry5.SymbolConstants;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.annotations.Startup;
import org.apache.tapestry5.ioc.services.ApplicationDefaults;
import org.apache.tapestry5.services.Context;
import org.hxzon.configdesigner.web.util.WebUtil;
import org.slf4j.Logger;

public class AppModule {

    @ApplicationDefaults
    public static void contributeApplicationDefaults(MappedConfiguration<String, String> configuration) {
        configuration.add(SymbolConstants.COOKIE_MAX_AGE, "14 d");
        configuration.add(SymbolConstants.HMAC_PASSPHRASE, "configDesigner");
    }

    @Startup
    public static void init(Context servletContext, Logger logger) {
        String contextRealPath = servletContext.getRealFile("/").getPath();
        logger.info("contextPath:" + contextRealPath);
        if (contextRealPath == null) {
            contextRealPath = "";
        }
        WebUtil.init(contextRealPath, contextRealPath + "/WEB-INF/upload/");
    }

//    @Contribute(NullFieldStrategySource.class)
//    public static void contributeNullFieldStrategySource(MappedConfiguration<String, NullFieldStrategy> configuration) {
//        configuration.override("default", new EmptyNullFieldStrategy());
//    }

}
